package main.Q1001_1100;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class Q1071_1080 {
	public static void main(String[] args) {
		System.out.println("Question1071：");
		System.out.println("Question1072：");
		System.out.println("Question1073：");
		System.out.println("Question1074：");
		System.out.println("Question1075：");
		System.out.println("Question1076：");
		System.out.println("Question1077：");
		System.out.println("Question1078：");
		System.out.println("Question1079：活字印刷");
		System.out.println("Question1080：");
	}
}

class Question1079 {
	public int numTilePossibilities(String tiles) {
		Map<Character, Integer> count = new HashMap<>();
		for (char t : tiles.toCharArray()) {
			count.put(t, count.getOrDefault(t, 0) + 1);
		}
		Set<Character> tile = new HashSet<>(count.keySet());
		return process(tiles.length(), count, tile) - 1;
	}

	private int process(int i, Map<Character, Integer> count, Set<Character> tile) {
		if (i == 0) {
			return 1;
		}
		int result = 1;
		for (char t : tile) {
			if (count.get(t) > 0) {
				count.put(t, count.get(t) - 1);
				result += process(i - 1, count, tile);
				count.put(t, count.get(t) + 1);
			}
		}
		return result;
	}
}